package com.schoolMall.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;

/**
 * @author:zyh
 * @Time:2021-08-30-14:50
 * @email:1269231889@qq.com
 */
public class JsonUtil {

    public static <T> T json2Object(String json,Class<T> clazz) throws IOException {
        ObjectMapper objectMapper = new ObjectMapper();
        T object = (T) objectMapper.readValue(json, clazz.getClass());
        return object;
    }
    public static  String object2Json(Object object) throws JsonProcessingException {
        ObjectMapper objectMapper = new ObjectMapper();
        String json = objectMapper.writeValueAsString(object);
        return json;
    }
}
